package Thread;/*
 *
 *@author:    Xavier
 *@data:      2024 - 01 - 13
 *@time:      14:03
 *
 */


//单利模式（饿汉模式）

class Singleton {
    private static Singleton instance = new Singleton();//这行代码 执行时机 是在Singleton类被jvm加载的时候

    public static Singleton getInstance() {
        return instance;
    }

    //作出一个实例，禁止别人去new这个实例！
    private Singleton() {}
}

public class Demo16 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();

        //Singleton s3 = new Singleton();

        System.out.println(s1 == s2);
        //System.out.println(s1 == s3);
    }
}
